let datetime = function (timepaker) {
    let time
    let timestamp = Date.parse(new Date())
    let startDate = timepaker
    startDate = startDate.replace(new RegExp('-', 'gm'), '/')
    let startDateM = (new Date(startDate)).getTime()
    let endDate = Number(timestamp) - Number(startDateM)
    let dtatms = parseFloat(endDate) / 1000
    let dateMinutes = parseInt(dtatms / 60)
    let dateHours = parseInt(dateMinutes / 60)
    let date = parseInt(dateHours / 24)
    let Month = parseInt(date / 30)
    let year = parseInt(Month / 12)
    if (dateHours >= 1 && dateHours < 24) {
        time = dateHours + '小时前'
    } else if (dateHours < 1) {
        time = dateMinutes + '分钟前'
    } else if (date >= 1 && date < 30) {
        time = date + '天前'
    } else if (Month >= 1 && Month < 12) {
        time = Month + '月前'
    } else if (year >= 1) {
        time = year + '年前'
    }
    return time
}

export default datetime
